<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn.
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author
 *
 */

namespace osc\mobile\controller;
use think\Db;
use think\Session;
use think\File;
use think\Request;
use osc\mobile\model\Member;

class User extends MobileBase
{
	protected function _initialize(){


		if (!Session::has("username")) {

            $this->redirect('login/login');

        }
		parent::_initialize();
		define('UID',is_login());
		//手机版

		if(!UID){
			$this->redirect('login/login');
		}




	}
	function yuanbao()
	{
        $username = session('username');
        if (!Member::is_status($username)) $this->error('您的账号已被禁用');
		$this->assign('top_title','元宝管理');
		$this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
		$this->assign('SEO',['title'=>'元宝管理-'.config('SITE_TITLE')]);
		return $this->fetch();
	}

    function consume()
    {
        $username = session('username');
        $goods_id=input('param.goods_id');

        $goods = Db::name('goods')->where('goods_id',$goods_id)->find();
        if($goods['type']==1)
        {
            $this->error('非提货商品');
        }

        $all_num = Db::name('programme')->where('username',$username)->where('state',3)->sum('number');
            //查询已经使用的记录
        $user_num = Db::name('use_ticket')->where('username',$username)->sum('number');

        $av_num = $all_num - $user_num;
        $this->assign('av_num',$av_num);
        $this->assign('goods',$goods);
        $this->assign('goods_id',$goods_id);
        $this->assign('top_title','提取现货');
        $this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
        $this->assign('SEO',['title'=>'提取现货-'.config('SITE_TITLE')]);
        return $this->fetch();
    }

    function use_pay()
    {
        $username = session('username');
        $id=input('param.id');

        if(!$id)
        {
            //获取最大的记录的id
            $id = Db::name('use_ticket')->where('username',$username)->max('id');
        }

        $use_ticket = Db::name('use_ticket')->where('id',$id)->find();


        $goods = Db::name('goods')->where('goods_id',$use_ticket['goods_id'])->find();


        $this->assign('use_ticket',$use_ticket);
        $this->assign('goods',$goods);
        $this->assign('top_title','提取现货');
        $this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
        $this->assign('SEO',['title'=>'提取现货-'.config('SITE_TITLE')]);
        return $this->fetch();
    }

    function use_list()
    {
        $username = session('username');


        $use_ticket = Db::name('use_ticket')->where('username',$username)->select();


        //$goods = Db::name('goods')->where('goods_id',$use_ticket['goods_id'])->find();


        $this->assign('list',$use_ticket);
        $this->assign('top_title','提取现货列表');
        $this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
        $this->assign('empty',"<span style='margin-left:20px;'>没有您数据，需要进行现货提货后，才有记录</span>");
        $this->assign('SEO',['title'=>'提取现货列表-'.config('SITE_TITLE')]);
        return $this->fetch();
    }

    function commit_use()
    {
         $username = session('username');

        if(request()->isPost()){

            $data=input('post.');

            if($data['number']=="")
            {
                return array('error'=>'请输入产品数量');
            }

            if(!(floor($data['number'])==$data['number']))
            {
                return array('error'=>'请输入正确的数量!');
            }

            if($data['address']=="")
            {
                return array('error'=>'请输入收货的地址');
            }

            if($data['number']<1)
            {
                return array('error'=>'请输入正确的数量');
            }

            if($data['accuser']=="")
            {
                return array('error'=>'请输入收货人姓名');
            }

            if($data['accmobile']=="")
            {
                return array('error'=>'请输入收货人电话');
            }


            //获取可用的提货克数
            //查询提货记录
            $all_num = Db::name('programme')->where('username',$username)->where('state',3)->sum('number');
            //查询已经使用的记录
            $user_num = Db::name('use_ticket')->where('username',$username)->sum('number');

            $goods = Db::name('goods')->where('goods_id',$data['goods_id'])->find();
            $av_num = $all_num - $user_num;
            $input_num = $data['number'] * $goods['pay_points'];
            if($av_num<$input_num)
            {
                return array('error'=>'可用提货数量不够!');
            }

            if($av_num==0)
            {
                return array('error'=>'可用提货数量不够!');
            }

            $price = $data['number']*$goods['price'];
            $map = [
                'username'  => $username,
                'goods_id'  => $data['goods_id'],
                'name'  => $goods['name'],
                'number'           => $data['number']*$goods['pay_points'],
                'num'           => $data['number'],
                'price'           => $price,
                'create_time'       => time(),
                'accuser'  => $data['accuser'],
                'address'  => $data['address'],
                'accmobile'  => $data['accmobile'],
            ];
            Db::name('use_ticket')->insert($map);


            return array('success'=>'提交成功','url'=>'/mobile/user/use_pay');
        }

    }

	function yuanbao_trans()
	{

        $username = session('username');

        if(request()->isPost()){

            $data=input('post.');

            $time = date('Hi',time());
            return array('error'=>'升级中');


            if($data['number']=="")
            {
                return array('error'=>'请输入转换数量');
            }

            if(!(floor($data['number'])==$data['number']))
            {
                return array('error'=>'请输入正确的数量!');
            }

            if($data['number']<1)
            {
                return array('error'=>'请输入正确的数量');
            }


            $pwd2 = think_ucenter_encrypt($data['pwd2'],config('PWD_KEY'));
            $user=Db::name('member')->where('username',$username)->find();
            if($pwd2!=$user['2password'])
            {
                return array('error'=>'二级密码输入有误');
            }



			$user=Db::name('member')->where('username',$username)->find();

            if($data['number'] > $user['jilin_bean'])
            {
                $error = '元宝不够!';
                return array('error'=> $error,'url'=>'/mobile/user/yuanbao_trans');
            }
            $map = [
                'token'		=> $data['token'],
                'username'	=> $username,
                'num'			=> $data['number'],
                'create_time'		=> time(),
            ];

            //存储兑换记录
            $res = Db::name('yuanbao_trans')->insert($map);

            //$member = new Member();

            //减少用户元宝数
            $red = Db::name('member')->where('username',$username)->setDec('jilin_bean',$data['number']);
			Db::name('member')->where('username',$username)->setInc('bao',$data['number']*2.1);
			Db::name('member')->where('username',$username)->setInc('jilt',$data['number']*2.1);

			 $this->bonus($username,$data['number']);
            if(!$res || !$red){
                if($res){
                    Db::name('jilin_ticket')->where('id',$res)->delete();
                }
                //if($red){
                    //$member->where('username',$username)->setInc('jilin_bean',$map['money']);
                //}
                return array('error'=>'申请失败','url'=>'/mobile/user/yuanbao_trans');
            }
            return array('success'=>'申请成功','url'=>'/mobile/user/yuanbao_trans');
        }

        $start = input('param.start');
        $end = input('param.end');
        if($start && $end){
            $map = [
                'username' => $username,
                'create_time' => array(['>',strtotime($start)],['<',strtotime($end)])
            ];
        }
        $map['username'] = $username;
        $list = Db::name('yuanbao_trans')
            ->where($map)
            ->order('create_time desc')
            ->paginate(10,false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        $page=$list->render(); //获取分页
//		print_r($variety);exit;
        $this->assign('start',$start);
        $this->assign('end',$end);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('top_title','元宝转换');
        return $this->fetch();

	}

	/**
     * 奖励结算
     * @param $username
     * @param $pro_id
     */
    function bonus($username,$sum){

        //查询提货赠送方案
        $info['total'] = $sum;

        $user = Db::name('member')->where('username',$username)->find();

        //给推荐人奖励

        $sharemobile = Db::name('member')->where('username',$user['sharemobile'])->find();

        if($sharemobile){
            if($sharemobile['user_state']>=1)
            {


                $tj_zong = $info['total']*0.10;

                if($sharemobile['bao']>$tj_zong*2)
                {
                    Db::name('member')->where('username',$sharemobile['username'])->setDec('jilt',$tj_zong);
                    Db::name('member')->where('username',$sharemobile['username'])->setInc('jilin_bean',$tj_zong);
                    $bonus['to_username'] = $username;
                    $bonus['username'] = $sharemobile['username'];
                    $bonus['num'] = $tj_zong;
                    $bonus['type'] = 0;
                    $bonus['create_time'] = time();
                    $bonus['remark'] = '释放-活动奖励';

                    Db::name('bonus')->insert($bonus);

                }

            }
        }


        /*
        //获取推荐人的推荐人
        if($sharemobile)
        {
             $upper_share = Db::name('member')->where('username',$sharemobile['sharemobile'])->find();



            if($upper_share){
                if($upper_share['user_state']>=1)
                {
                    $s1count = Db::name('member')->where('sharemobile',$upper_share['username'])->count();
                    //$s1count = 5;
                    if($s1count>=5)
                    {
                        $tj2_zong = $info['total']*0.10;

                        Db::name('member')->where('username',$upper_share['username'])->setInc('bao',$tj2_zong/2);
                        Db::name('member')->where('username',$upper_share['username'])->setInc('jilt',$tj2_zong/2);

                        $bonus_share1['to_username'] = $username;
                        $bonus_share1['username'] = $upper_share['username'];
                        $bonus_share1['num'] = $tj2_zong;
                        $bonus_share1['type'] = 0;
                        $bonus_share1['create_time'] = time();
                        $bonus_share1['remark'] = '二代推荐';

                        Db::name('bonus')->insert($bonus_share1);

                    }
                }

            }
        }
        */

        /*
        //给区域代理奖励
        $area_team = Db::name('agent_area')->where('id6',$user['id6'])->find();

        if($area_team)
        {
            $area_zong = $info['total']*0.05;

            Db::name('member')->where('username',$area_team['username'])->setInc('bao',$area_zong/2);
            Db::name('member')->where('username',$area_team['username'])->setInc('jilt',$area_zong/2);

            $bonus_area['to_username'] = $username;
            $bonus_area['username'] = $area_team['username'];
            $bonus_area['num'] = $area_zong;
            $bonus_area['type'] = 1;
            $bonus_area['create_time'] = time();
            $bonus_area['remark'] = '代理区域';
            Db::name('bonus')->insert($bonus_area);
        }
        */


        //给服务中心奖励
        $service = $this->getshareservice($username);

        //给团队代理奖励
        if($service)
        {
            $team_zong = $info['total']*0.03;
            $team_user = Db::name('member')->where('username',$service)->find();
            if($team_user['bao']>($team_zong*2))
            {
                Db::name('member')->where('username',$service)->setDec('jilt',$team_zong);
                Db::name('member')->where('username',$service)->setInc('jilin_bean',$team_zong);
                $bonus_team['to_username'] = $username;
                $bonus_team['username'] = $service;
                $bonus_team['num'] = $team_zong;
                $bonus_team['type'] = 0;
                $bonus_team['create_time'] = time();
                $bonus_team['remark'] = '服务中心释放-活动奖励';
                Db::name('bonus')->insert($bonus_team);
            }


        }

        $team = $this->getshareagent($username);

        if($team)
        {
            $team_zong = $info['total']*0.05;
            $team_user = Db::name('member')->where('username',$team)->find();
            if($team_user['bao']>($team_zong*2))
            {
                Db::name('member')->where('username',$team)->setDec('jilt',$team_zong);
                Db::name('member')->where('username',$team)->setInc('jilin_bean',$team_zong);
                $bonus_team['to_username'] = $username;
                $bonus_team['username'] = $team;
                $bonus_team['num'] = $team_zong;
                $bonus_team['type'] = 1;
                $bonus_team['create_time'] = time();
                $bonus_team['remark'] = '代理释放-活动奖励';
                Db::name('bonus')->insert($bonus_team);
            }


        }

        //给代理的代理奖励
        $shareagent = $this->getshareagent($team);


        if($shareagent)
        {
            $shareagent_zong = $info['total']*0.02;

            Db::name('member')->where('username',$shareagent)->setDec('jilt',$shareagent_zong);
            Db::name('member')->where('username',$shareagent)->setInc('jilin_bean',$shareagent_zong);
            $bonus_team['to_username'] = $username;
            $bonus_team['username'] = $shareagent;
            $bonus_team['num'] = $shareagent_zong;
            $bonus_team['type'] = 1;
            $bonus_team['create_time'] = time();
            $bonus_team['remark'] = '代理发展释放-活动奖励';
            Db::name('bonus')->insert($bonus_team);
        }

    }

    /**
     * 递归查询代理
     * @param $username
     * @return mixed|null
     */
    function getshareagent($username)
    {

        if(!$username)
        {
            return null;
        }
        $user = Db::name('member')->where('username',$username)->find();

        $shareuser = Db::name('member')->where('username',$user['sharemobile'])->where('user_state >= 2 and user_state <= 6')->find();

//        echo'<pre>';print_r($shareuser);

        $agent = Db::name('agent')->where('username',$user['sharemobile'])->where('state=1 or state = 0')->find();
//        echo'<pre>';print_r($agent);exit;
        if($shareuser)
        {

            return $shareuser['username'];

        }else
        {

            return $this->getshareagent($user['sharemobile']);

        }


    }

    /**
     * 递归查询服务中新
     * @param $username
     * @return mixed|null
     */
    function getshareservice($username)
    {

        if(!$username)
        {
            return null;
        }
        $user = Db::name('member')->where('username',$username)->find();

        $shareuser = Db::name('member')->where('username',$user['sharemobile'])->where('user_state >= 2 and user_state <= 6')->find();

        $shareuser1 = Db::name('member')->where('username',$user['sharemobile'])->where('user_state = 9')->find();
//        echo'<pre>';print_r($shareuser);

        $agent = Db::name('agent')->where('username',$user['sharemobile'])->where('state=1 or state = 0')->find();
//        echo'<pre>';print_r($agent);exit;
        if($shareuser)
        {

            return null;

        }else if($shareuser1)
        {

            return $shareuser1['username'];

        }else
        {
            return $this->getshareservice($user['sharemobile']);
        }


    }

	function index(){

		if (!Session::has("username")) {

            $this->redirect('login/login');

        }

        $username = session('username');
        $userinfo = Db::name('member')->where('username',$username)->find();

        $map['state'] = array('lt',2);
        $agent = Db::name('agent')->where('username',$username)->where($map)->find();

        if(!$userinfo['idcardname'])
        {
        	$this->redirect('user/updateidcard?id=1');
        }
        $bank = Db::name('user_bank')->where('username',$username)->find();

        if(!$bank)
        {
        	$bank['bankname']='未设置';
        	$bank['bankaccountname']='';
        	$bank['bankaccount']='';

        }

        $name="游客";
        if($userinfo['user_state']>0)
        {
			if(0<= $userinfo['share_count'] and $userinfo['share_count'] < 2){
				$name="VIP会员";
			}else if(2<= $userinfo['share_count'] and $userinfo['share_count'] < 5){
				$name="一级会员";
			}else if(5<= $userinfo['share_count'] and $userinfo['share_count'] < 8){
				$name="二级会员";
			}else{
				$name="三级会员";
			}
        }
        if($agent)
        {
        	$name="代理";
        }
//		echo'<pre>';print_r($userinfo);exit;

		$this->assign('agent',$agent);
		$this->assign('no_pay',$this->order_count(config('default_order_status_id')));
		$this->assign('paid',$this->order_count(config('paid_order_status_id')));
		$this->assign('userinfo',$userinfo);
		$this->assign('name',$name);
		//$this->assign('area',$area);
		$this->assign('bank',$bank);
		$this->assign('SEO',['title'=>'个人中心-'.config('SITE_TITLE')]);

		$this->assign('flag','user');

		return $this->fetch();
	}

	function help()
	{
		return $this->fetch();
	}

	function substr_cut($user_name)
	{
	    $strlen     = mb_strlen($user_name, 'utf-8');
	    $firstStr     = mb_substr($user_name, 0, 1, 'utf-8');
	    $lastStr     = mb_substr($user_name, -1, 1, 'utf-8');
	    return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
	}

	function order_count($status){
		return count(Db::name('order')->where(array('order_status_id'=>$status,'uid'=>UID))->select());
	}

	function wish_list(){

		$this->assign('top_title','我的收藏');
		$this->assign('SEO',['title'=>'我的收藏-'.config('SITE_TITLE')]);
		return $this->fetch();
	}

	function ajax_wish_list(){

    	$page=(int)input('param.page');//页码

		$limit = (6 * $page) . ",6";

		$list= Db::view('Goods','goods_id,image,price,name')
		->view('MemberWishlist','uid','Goods.goods_id=MemberWishlist.goods_id')
		->where(array('MemberWishlist.uid'=>UID))->limit($limit)->select();

		if(isset($list)&&is_array($list)){
			foreach ($list as $k => $v) {
				$list[$k]['image']=resize($v['image'], 200, 200);
			}
		}

		return $list;

	}

	function remove_wish(){
		osc_service('common','member')->remove_wish(input('param.id'),UID);
		storage_user_action(UID,member('nickname'),config('FRONTEND_USER'),'删除了收藏');

		$this->redirect('User/wish_list');
	}


	/**
	 * 修改密码
	 * @return array|mixed
	 */
	function updateuserpasswd()
	{
		if(request()->isPost()){
			$data=input('post.');
//			var_dump($data);exit;
			$r=osc_service('common','Member')->updateuserpasswd($data);
			if(isset($r['error'])){
				return $r;
			}
			return array('success'=>'修改密码成功','url'=>'/mobile');

		}

		$this->assign('top_title','修改密码');
		$this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
		$this->assign('SEO',['title'=>'修改密码-'.config('SITE_TITLE')]);

		$this->assign('flag','user');

		return $this->fetch();
	}


	/**
	 * 修改二级密码
	 * @return array|mixed
	 */
	function updateuser2passwd()
	{
		if(request()->isPost()){
			$data=input('post.');
			//var_dump($data);
			$r=osc_service('common','Member')->updateuser2passwd($data);
			if(isset($r['error'])){
				return $r;
			}
			return array('success'=>'修改二级密码成功','url'=>'/mobile');

		}
		$this->assign('top_title','修改二级密码');
		$this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
		$this->assign('SEO',['title'=>'修改二级密码-'.config('SITE_TITLE')]);

		$this->assign('flag','user');

		return $this->fetch();

	}

	/**
	 * 实名认证
	 * @return array|mixed
	 */
	function updateidcard()
	{
		$info=null;
       	if(request()->isPost()){
			$data=input('post.');
			//var_dump($data);
			$r=osc_service('common','Member')->updateidcard($data);
			if(isset($r['error'])){
				return $r;
			}
			return array('success'=>'提交实名认证信息成功','url'=>'/mobile');
		}
		if(request()->isGet())
		{
			$data=input('param.');
			if($data){
				if($data['id']==1)
				{
					$info="您还没有做实名认证，请先做实名认证处理";
				}
			}
		}
		$username = session("username");
        $user=Db::name('member')->where('username',$username)->find();
        if($user['isauth']!=0)
        {
        	$this->redirect(url('/mobile/user/userindex'));
        }

       	$this->assign('top_title','实名认证');
		$this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
		$this->assign('SEO',['title'=>'实名认证'.config('SITE_TITLE')]);

		$this->assign('flag','user');
		$this->assign('info',$info);

		return $this->fetch();

	}

	/**
	 * 绑定银行信息
	 * @return array|mixed
	 */
	function updatebank()
	{
		if(request()->isPost()){
			$data=input('post.');
			//var_dump($data);
			$r=osc_service('common','Member')->updatebank($data);
			if(isset($r['error'])){
				return $r;
			}
			return array('success'=>'提交银行信息成功','url'=>'/mobile');

		}
		$username = session("username");
		$bank = Db::name('user_bank')->where('username',$username)->find();
       	$this->assign('bank',$bank);
       	$this->assign('top_title','更新银行卡信息');
		$this->assign('userinfo',Db::name('member')->where('uid',UID)->find());
		$this->assign('SEO',['title'=>'更新银行卡信息'.config('SITE_TITLE')]);

		$this->assign('flag','user');

		return $this->fetch();

	}

	public function updatearear()
	{
       	$this->assign('top_title','更新用户归属信息');

		$this->assign('SEO',['title'=>'更新用户归属信息'.config('SITE_TITLE')]);
		return $this->fetch();
	}

	public function send2bank()
	{
		//$data=input('post.');
		//var_dump($data);
		//$data['mobile']  = $data['from_user'] = $mobile = trim(input('post.username', null));
		//echo $data['mobile'];
		//echo "infosys";
		//$this->sendsms($data['mobile']);
		$mobile = session("username");

		$ret = "0";
		if($mobile)
		{
           $r=osc_service('common','Member')->sendsms_common($mobile,'updatebank');

		}

		//retrun $ret;
	}

	function userindex()
	{

		$username = session('username');
        $userinfo = Db::name('member')->where('username',$username)->find();
        $bank = Db::name('user_bank')->where('username',$username)->find();

        if(!$bank)
        {
        	$bank['bankname']='未设置';
        	$bank['bankaccountname']='未设置';
        	$bank['subbankname']='未设置';
        	$bank['bankaccount']='未设置';

        }
        $prv = Db::name('area')->where('area_id',$userinfo['province_id'])->find();
        $city = Db::name('area')->where('area_id',$userinfo['city_id'])->find();
        $country = Db::name('area')->where('area_id',$userinfo['country_id'])->find();

        $area = $prv['area_name'].' '.$city['area_name'].' '.$country['area_name'];


        if($userinfo['isauth']==0)
        {
        	$userinfo['idcardname'] = '未实名认证';
        	$userinfo['idcard'] = '未实名认证';
        }
		$this->assign('top_title','个人信息面板');
		$this->assign('userinfo',$userinfo);
		$this->assign('bank',$bank);
		$this->assign('area',$area);
		$this->assign('SEO',['title'=>'个人信息面板-'.config('SITE_TITLE')]);

		$this->assign('flag','user');

		return $this->fetch();
	}

	function exchange_trade(){
		$user = session('username');
		$house = Db::name('exchange_house')->where(['state'=>1])->field('id,name')->select();

		foreach($house as &$value){
			$map = [
				'username' => $user,
				'exchange_id'	=> $value['id']
			];
			$value['status'] = DB::name('exchange_trade_acc')->where($map)->count();
		}
		$this->assign('house',$house);
		$this->assign('top_title','交易所帐号管理');
		return $this->fetch();
	}

	function updatetrade(){
		$id = input('param.id/d');
		$uid = session('username');
		$user = Db::name('member')->where(['username'=> $uid])->find();
		$user['idcard'] = substr_replace($user['idcard'],"***********",3,11);
		$trade_acc = Db::name('exchange_trade_acc')->where(['exchange_id'=>$id,'username'=>$uid])->find();
		$trade = Db::name('exchange_house')->where(['id'=>$id])->find();
		$this->assign('trade_acc',$trade_acc);
		$this->assign('trade',$trade);
		$this->assign('user',$user);
		$this->assign('top_title','交易所帐号绑定');
		return $this->fetch();
	}

	/**
	 * 绑定交易所信息
	 * @return array
	 * @throws \think\Exception
	 */
	function tradeadd(){
		$data = input('post.');
		if($data['trade_id'] == ''){
			return array('error'=>'主账号不能为空');
		}
		if($data['trade_id'] != $data['trade_id_ss']){
			return array('error'=>'两次主账号不一致');
		}
		$map = [
			'exchange_id'=>$data["exchange_id"],
			'username'=>$data['username']
		];

		$is_acc = Db::name('exchange_trade_acc')->where('trade_id',$data['trade_id'])->find();

		if($is_acc){
			return array('error'=>'您填写的账号已被使用，请重新填写');
		}

		$trade_acc = Db::name('exchange_trade_acc')->where($map)->find();

		if(empty($trade_acc)){
			$info = [
				'username' => $data['username'],
				'exchange_id'=>$data["exchange_id"],
				'trade_id'	=> $data['trade_id'],
				'sub_trade_id'	=> $data['sub_trade_id'],
			];

			$res = Db::name('exchange_trade_acc')->insert($info);
			if($res){
				return array('success'=>'交易所帐号绑定成功','url'=>'/exchange_trade');
			}else{
				return array('error'=>'交易所帐号绑定失败');
			}
		}else{

			$info = [
					'trade_id' => $data['trade_id'],
					'sub_trade_id'	=> $data['sub_trade_id'],
			];
			$res = Db::name('exchange_trade_acc')->where($map)->update($info);
			if($res){
				return array('success'=>'交易所帐号修改成功','url'=>'/exchange_trade');
			}else{
				return array('error'=>'交易所帐号修改失败');
			}
		}
	}

	public function doUpload(){
		$files = request()->file('image');
//		echo"<pre>";print_r(ROOT_PATH);exit;
		if($files){
			$info="";
			foreach($files as $picFile){

				// 移动到框架应用根目录/public/uploads/ 目录下
				$info = $picFile->move(ROOT_PATH.'/public/uploads'.DS.'images');


				/*获取存储路径，以便插入数据库*/
				/* $path= "/uploads/images/".$info->getSaveName();*/

			}
			if($info!==""){
				$this->success($info);
				// 成功上传后 获取上传信息
				// 输出 jpg
				/* echo $info->getExtension();*/
				// 输出 42a79759f284b767dfcb2a0197904287.jpg
				/*echo $info->getFilename();*/
			}else{
				// 上传失败获取错误信息
				/* echo $file->getError();*/
				$this->error('上传失败！');
			}
		}
	}

}
